package org.hackystat.projectbrowser.page.projects;

import java.util.ArrayList;
import java.util.List;
import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.hackystat.ambientdevice.server.jaxb.Project;
import org.hackystat.projectbrowser.ProjectBrowserSession;
import org.hackystat.projectbrowser.page.chooseTAP.ChooseTAP;

/**
 * The list view that lists the projects that a user has. 
 * 
 * @author Edward Kim
 *
 */
public class ProjectTable extends ListView {

  /** Supports serialization. */
  private static final long serialVersionUID = 1L;

  private List<Project> listOfProject = new ArrayList<Project>();
  private Project project = new Project();

  /**
   * The table that lists the projects. 
   * @param id provided for the super class (not really needed).
   */
  public ProjectTable(String id) {
    super(id);
    listOfProject = ProjectBrowserSession.get().getProjectsFromXML();
    setList(listOfProject);
  }

  /**
   * Populates the list. 
   * @param item The items that will be in the list. 
   */
  @Override
  protected void populateItem(ListItem item) {
    PageParameters param = new PageParameters();
    project = (Project) item.getModelObject();
    param.put("projectName", project.getProjectName());

    item.add(new Label("projectName", project.getProjectName()));
    item.add(new BookmarkablePageLink("projectLink", ChooseTAP.class, param));
  }

}
